<?php
class Application_Model_Articles extends Zend_Db_Table_Abstract {
	protected $_name = 'news_article';
	protected $_primary = 'article_id';
	
	public function getMetadata()
	{
		if(empty($this->_metadata))
		{
			$this->_setupMetadata();
		}
		return $this->_metadata;
	}
	
	/**
	 * 
	 * Tim kiem mot dong trong bang
	 * @param Int $article_id
	 */
	public function _find($article_id) {
        try 
        {
            $row = parent::find($article_id)->current();
            return Utility_Converter::arrayToObject($row->toArray());
        }catch(Zend_Db_Exception $ex) 
        {
            throw $ex;
        }
	}
	
	/**
	 * 
	 * Enter description here ...
	 * @param Object $object
	 */
	public function _insert($object) {
		try {
			$object->article_id = null;
			$data = Utility_Converter::objectToArray($object);
			return parent::insert($data);
		}
		catch (Zend_Db_Exception $ex) {
			throw $ex;
		}
	}
	
	public function _delete($article_id) {
		try 
		{
			$where = parent::getAdapter()
					->quoteInto('article_id = ?', $article_id);
			return parent::delete($where);
		}
		catch (Zend_Db_Exception $ex) {
			throw $ex;
		}
	}
	
	/**
	 * 
	 * Update news_article data
	 * @param Object $object
	 */
	public function _update($object){
		try {
			$adapter = parent::getAdapter();
			$where = $adapter->quoteInto('article_id = ?', $object->article_id);
			$data = Utility_Converter::objectToArray($object);
			return parent::update($data, $where);
		} catch(Zend_Db_Exception $ex) {
			throw $ex;		
		}
	}
	
}